package servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Book;
import service.ShopManager;
import service.impl.ShopManagerFactory;
import utils.BookMap;

/**
 * Servlet implementation class AddCartServlet
 */
public class AddCartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ShopManager manager;   
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddCartServlet() {
        super();
        manager = ShopManagerFactory.getInstance();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bid = request.getParameter("bid");
		if(bid!=null){
			Map<String, Integer> bookMap = BookMap.getBookMap();
			if(bookMap.containsKey(bid)){
				bookMap.put(bid, bookMap.get(bid)+1);
			}else{
				bookMap.put(bid, 1);
			}
		}
		
		request.getRequestDispatcher("bookList").forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
